namespace SinaFinanceBaseClassLibrary
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Shapes;

    public class CandleStick : UserControl
    {
        private Color candleColor = Colors.Red;
        private Point candleStickLeftButtomPoint = new Point();
        private Point candleStickLeftTopPoint = new Point();
        private Point candleStickLineButtomPoint = new Point();
        private Point candleStickLineTopPoint = new Point();
        private Point candleStickRightButtomPoint = new Point();
        private Point candleStickRightTopPoint = new Point();
        private Canvas parentCanvas;

        public void RenderCandleStick()
        {
            Line line = new Line {
                X1 = this.candleStickLineTopPoint.X,
                Y1 = this.candleStickLineTopPoint.Y,
                X2 = this.candleStickLineButtomPoint.X,
                Y2 = this.candleStickLineButtomPoint.Y,
                StrokeThickness = 0.5,
                Stroke = new SolidColorBrush(this.candleColor)
            };
            this.parentCanvas.Children.Add(line);
            if (!this.candleStickLeftTopPoint.Y.Equals(this.candleStickLeftButtomPoint.Y))
            {
                Polygon polygon = new Polygon {
                    Points = { this.candleStickLeftTopPoint, this.candleStickRightTopPoint, this.candleStickRightButtomPoint, this.candleStickLeftButtomPoint },
                    Fill = new SolidColorBrush(this.candleColor)
                };
                this.parentCanvas.Children.Add(polygon);
            }
            else
            {
                Line line2 = new Line {
                    X1 = this.candleStickLeftTopPoint.X,
                    Y1 = this.candleStickLeftTopPoint.Y,
                    X2 = this.CandleStickRightTopPoint.X,
                    Y2 = this.candleStickLeftTopPoint.Y,
                    StrokeThickness = 0.5,
                    Stroke = new SolidColorBrush(this.candleColor)
                };
                this.parentCanvas.Children.Add(line2);
            }
        }

        public Color CandleColor
        {
            get
            {
                return this.candleColor;
            }
            set
            {
                this.candleColor = value;
            }
        }

        public Point CandleStickLeftButtomPoint
        {
            get
            {
                return this.candleStickLeftButtomPoint;
            }
            set
            {
                this.candleStickLeftButtomPoint = value;
            }
        }

        public Point CandleStickLeftTopPoint
        {
            get
            {
                return this.candleStickLeftTopPoint;
            }
            set
            {
                this.candleStickLeftTopPoint = value;
            }
        }

        public Point CandleStickLineButtomPoint
        {
            get
            {
                return this.candleStickLineButtomPoint;
            }
            set
            {
                this.candleStickLineButtomPoint = value;
            }
        }

        public Point CandleStickLineTopPoint
        {
            get
            {
                return this.candleStickLineTopPoint;
            }
            set
            {
                this.candleStickLineTopPoint = value;
            }
        }

        public Point CandleStickRightButtomPoint
        {
            get
            {
                return this.candleStickRightButtomPoint;
            }
            set
            {
                this.candleStickRightButtomPoint = value;
            }
        }

        public Point CandleStickRightTopPoint
        {
            get
            {
                return this.candleStickRightTopPoint;
            }
            set
            {
                this.candleStickRightTopPoint = value;
            }
        }

        public Canvas ParentCanvas
        {
            get
            {
                return this.parentCanvas;
            }
            set
            {
                this.parentCanvas = value;
            }
        }
    }
}
